﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Classes;
using FlightSystemDBLayer;

namespace FlightSystemControlLayer
{
    public class BookingCtr
    {
        private static Object ob = new Object();
        IBooking bookDB;
        
        public BookingCtr() 
        {
            bookDB = new DBBooking();
            
        }
        public void Book(Connection conn, int seatsWanted, string fname, string lname, string address, string country, string phone, string email, string passport)
        {
            lock (ob)
            {
                Booking book = new Booking();

                try
                {
                    bookDB.writeConnection(conn, seatsWanted);
                    foreach (Reservation item in book.book(conn, seatsWanted, fname, lname, address, country, phone, email, passport))
                    {


                        bookDB.writeData(item);

                    }
                }
                catch (Exception e)
                {

                    Console.WriteLine(e.StackTrace);
                }
            }
            
        }
    }
}
